package com.scy.java.io.convert;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

//OutputStreamReader转化流，
//将字符转化为字节
public class ConvertStreamWriterTest {
    public static void main(String[] args) {
        try {
            //创建转化流对象 编码默认是UTF-8
            OutputStreamWriter osw =
                    new OutputStreamWriter(
                            new FileOutputStream("out.txt"));
            osw.write("犯我中华者，虽远必诛");
            osw.close();
            //创建转化流对象,指定编码格式
            //指定GBK编码中文输出乱码
            OutputStreamWriter osw2 =
                    new OutputStreamWriter(
                            new FileOutputStream("out.txt")
                            //中文乱码
//                    ,"GBK"
                    );
            osw2.write("上帝vu华德福别人");
            osw2.close();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
